const twitterGetUrl = require("twitter-url-direct");

module.exports = async (url) => {
  let rst;
  let response = await twitterGetUrl(url);
  console.log(response);
  if (!response.found || !response.download || !response.download.length) {
    return null;
  }
  let currWidth = 0;
  response.download.forEach((n) => {
    const { width, url } = n;
    if (currWidth < width - 0) {
      currWidth = width - 0;
      rst = url;
    }
  });

  if (!rst) {
    rst = response.download[response.download.length - 1].url;
  }

  return rst;
};
